from datetime import datetime

def refine_val(typ, val) :
    """
     Exceptions :
        ValueError for float, int, time and date types
    """
    ret_val = None
    if typ == "TEXT" :
        if val != "":
            ret_val = val
    else :
        val = ' '.join(val.upper().split())
        if val != "" : # Check if user has given all spaces
            if typ == "INT" :
                ret_val = int(val) 
            elif typ == "FLOAT" :
                ret_val = float(val)
            elif typ == "CHAR" or typ == "CHAR_UNIQ" :
                ret_val = val
            elif typ == "DATE" :
                print val
                dt = datetime.strptime(val, '%d %b %Y')
                print dt
                ret_val = dt.date()
    return ret_val